home *** CD-ROM | disk | FTP | other *** search
- > why does this cause me to get an "Out of stack space" Error and
- > what can I do to remedy it?
- -----<Program (slightly "compressed") follows>-----
- > S1
- > Procedure S1
- > Paper 0 : Centre "Procedure S1 Here!"
- > Wait 1 : Cls 0 : S2
- > End Proc
- > Procedure S2
- > Paper 0 : Centre "Procedure S2 Here!"
- > Wait 1 : Cls 0 : S1
- > End Proc
- > Do : Loop
-
- Well, stack space is limited. The program begins by calling the
- procedure S1 which in turn calls procedure S2 which calls
- procedure S1 which calls procedure S2 calls S1 calls S2 calls
- S1 calls S2 S1 S2 S1 S2 S1 S2... Phew - finally broke out!!
-
- Everytime you call a procedure (or Gosub a routine) some data is
- pushed onto the stack, at the end of the procedure this data is
- retrieved from the stack. However, both of your procedures are
- calling each other instead of exiting, so the data is never removed
- from the stack where it keeps accumulating until finally you have
- completely filled all available stack space...
-
- How can you remedy this?
- Well, you need to take a good look at what you're trying to do...
- why do you want these procedures to call each other in an endless
- loop like that?
-
- If you're trying for some type of recursion, you need to insert a
- counter in these procedures some place.
-
- -----<REVISED CODE BEGINS HERE>-----
- GLOBAL COUNTER
- Procedure S1
- Paper 0 : Centre "Procedure S1 Here!"
- Wait 1 : Cls 0
- S2
- End Proc
- Procedure S2
- Paper 0 : Centre "Procedure S2 Here!"
- Wait 1 : Cls 0 : S1
- Inc COUNTER
- If COUNTER<5 Then S1
- End Proc
- COUNTER=0 : S1
- Do
- Loop
- -----<REVISED CODE ENDS HERE>---
-
- Of course, as usual I'm typing this on my PC, so I don't really know
- how well this will work... ;-) You need to determine exactly what
- it is you're trying to accomplish as there is most likely a better
- way to achieve what you're after. :-)
-
-
- Garfield Benjamin e-mail:gbenjam@sosbbs.com
- Website( http://www.sosbbs.com/~gbenjam ): 50% Complete
-
-